home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue24 / clinic / CAPTURE3.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-04-28  |  1.4 KB  |  70 lines

  1. unit Capture3U;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, ExtCtrls, ExtDlgs;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Img: TImage;
  12.     SaveDlg: TSavePictureDialog;
  13.     LoadDlg: TOpenPictureDialog;
  14.     Panel1: TPanel;
  15.     Button1: TButton;
  16.     Button2: TButton;
  17.     Button3: TButton;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure Button2Click(Sender: TObject);
  20.     procedure Button3Click(Sender: TObject);
  21.   private
  22.     { Private declarations }
  23.   public
  24.     { Public declarations }
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.DFM}
  33.  
  34. procedure TForm1.Button1Click(Sender: TObject);
  35. const
  36.   NumColors = 256;
  37. var
  38.   R: TRect;
  39.   C: TCanvas;
  40.   P: TMaxLogPalette;
  41. begin
  42.   R := Img.BoundsRect;
  43.   C := TCanvas.Create;
  44.   C.Handle := GetDC(HWnd_Desktop);
  45.   try
  46.     Img.Canvas.CopyRect(R, C, R);
  47.     P.palVersion := $300;
  48.     P.palNumEntries := NumColors;
  49.     GetSystemPaletteEntries(C.Handle, 0, NumColors, P.palPalEntry);
  50.     Img.Picture.Bitmap.Palette := CreatePalette(PLogPalette(@P)^);
  51.   finally
  52.     ReleaseDC(HWnd_Desktop, C.Handle);
  53.     C.Free;
  54.   end;
  55. end;
  56.  
  57. procedure TForm1.Button2Click(Sender: TObject);
  58. begin
  59.   if SaveDlg.Execute then
  60.     Img.Picture.Bitmap.SaveToFile(SaveDlg.FileName)
  61. end;
  62.  
  63. procedure TForm1.Button3Click(Sender: TObject);
  64. begin
  65.   if LoadDlg.Execute then
  66.     Img.Picture.Bitmap.LoadFromFile(LoadDlg.FileName)
  67. end;
  68.  
  69. end.
  70.